// 登录弹窗

import {useState} from "react";
import Taro from "@tarojs/taro";
import {wxActions} from "../utils/wxActions";

export function useLoginMask(dispatch) {
    const [loginMask, setLoginMask] = useState(false);

    // 关闭登录阻拦弹窗
    const closeLoginMask = () => {
        setLoginMask(false);
    }

    // 打开登录阻拦弹窗
    const openLoginMask = () => {
        setLoginMask(true);
    }

    // 获取用户信息
    const getUserInfo = (e) => {
        const successCallback = () => {
            Taro.hideLoading()
            setLoginMask(false);
        };
        const failCallback = () => {
            Taro.hideLoading()
            wxActions.showTip("登录失败")
        }
        wxActions.showLoading("登录中")
        wxActions.autoLogin(dispatch, successCallback, failCallback);
    }

    return [loginMask, closeLoginMask, openLoginMask, getUserInfo]
}
